package logic

import (
	"context"
	"recharge_srv/rechargeclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrderLogic {
	return &AddOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddOrderLogic) AddOrder(req *types.AddOrderrequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.RechargeSrv.AddOrder(l.ctx, &rechargeclient.AddOrderRequest{
		UserId:       req.UserId,
		RechargeTIme: req.RechargeTIme,
		Amount:       req.Amount,
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 400,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "订单添加成功",
		Code: 200,
		Data: add,
	}, nil
}
